home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
c80tcog.lbr
/
ATOI.CQ
/
atoi.c
Wrap
Text File
|
1985-08-09
|
1KB
|
55 lines
/* atoi - convert string s to integer */
/* Version 1.1 1982/11/15 22:09 */
/* Kernighan, Brian W. & Ritchie, Dennis M.
"The C Programming Language", Prentice-Hall,
Englewood Cliffs, NJ, 1978, p. 58 */
#ifdef MAINLY
#else
#include "c80def.h"
#endif
atoi(s) char *s;
{
register int i, n;
register Boolean pos;
static char Version[]= "Version 1.1 1982/11/15 22:09";
for (i=0; *s == ' ' || *s == '\t' || *s == '\n'; s++)
/* skip white space */;
if (*s == '+' || *s == '-')
pos= *s++ == '+';
else
pos= YES;
for (n= 0; '0' <= *s && *s <= '9'; s++) {
n*= 10;
n-= *s - '0';
}
return(pos ? -n:n);
} /* atoi */
#ifdef MAINLY
#else
#ifdef CP_M
extern FILE *STDIN, *STDOUT;
#endif
#include "printf.c"
#define MAINLY
#include "itoa.c"
#include "strchr.c"
main() {
register int i;
char s[10];
for (i= -1; i < 0; i--)
if(atoi(itoa(i, s)) != i)
printf("Test failed for %d\n", i);
for (i= (~0) >> 1; i; i--)
if (atoi(itoa(i,s)) != i)
printf("Test 2 failed for %d\n", i);
} /* main */
abs(x) int x;
{return(x < 0? -x:x);}
#endif